<?php

namespace plugin\admin\app\service\v1;

use plugin\admin\app\constant\v1\CommonConstant;

/**
 * 服务类
 **/
class RuleService
{

    /**
     * 获取菜单
     *
     * @param array $menus
     * @param array $admin
     **/
    public static function get($menus, $admin)
    {
        $data = [];
        $data_0 = 0;
        $data[0] = [
            "id" => $data_0,
            "title" => "系统首页",
            "icon" => "layui-icon layui-icon-circle-dot",
            "key" => "plugin\admin\app\controller\IndexController",
            "pid" => 0,
            "created_at" => "",
            "updated_at" => "",
            "href" => "/app/admin/index/dashboard",
            "type" => 1,
            "weight" => 0,
            "user_status" => 1,
            "name" => "系统首页",
            "value" => $data_0,
        ];
        if ($admin['user_status'] == CommonConstant::DEFAULT_1) {
            $menus = array_merge($data, $menus);
            return $menus;
        }

        $config = OptionService::getConfig('logo');
        list($line_list, $line_column) = LineService::select(['id','name']);

        $data_1 = 1000;
        $data[1] = [
            "id" => $data_1,
            "title" => "软件下载",
            "icon" => "layui-icon layui-icon-circle-dot",
            "key" => "download",
            "pid" => 0,
            "created_at" => "",
            "updated_at" => "",
            "href" => $config['download_url'],
            "type" => 1,
            "weight" => 0,
            "user_status" => 1,
            "name" => "软件下载",
            "value" => $data_1,
        ];
        $data_2 = 1001;
        $data[2] = [
            'id' => $data_2,
            "title" => "节点购买",
            "icon" => "layui-icon layui-icon-circle-dot",
            "key" => "buynodes",
            "pid" => 0,
            "created_at" => "",
            "updated_at" => "",
            "href" => "",
            "type" => 0,
            "weight" => 0,
            "user_status" => 1,
            "name" => "节点购买",
            "value" => $data_2,
        ];
        $children = [];
        foreach ($line_list as $key => $value) {
            $new_key = $key + 1;
            $id = $data_2 + $new_key;
            $line_id = $id . '0';
            $children[$key] = [
                'id' => $id,
                "title" => $value['name'],
                "icon" => "",
                "key" => "games",
                "pid" => $data_2,
                "created_at" => "",
                "updated_at" => "",
                "href" => "",
                "type" => 0,
                "weight" => 0,
                "user_status" => 1,
                "name" => $value['name'],
                "value" => $id,
                "children" => [],
            ];
            $line_children = [
                [
                    'id' => (integer)$line_id + 1,
                    "title" => '购买节点',
                    "icon" => "",
                    "key" => "plugin\admin\app\controller\V1NodeController",
                    "pid" => $id,
                    "created_at" => "",
                    "updated_at" => "",
                    "href" => "/app/admin/v1-node/buynodes?line_id=" . $value['id'],
                    "type" => 1,
                    "weight" => 0,
                    "user_status" => 1,
                    "name" => '购买节点',
                    "value" => (integer)$line_id + 1,
                ],
                [
                    'id' => (integer)$line_id + 2,
                    "title" => '所有订单',
                    "icon" => "",
                    "key" => "plugin\admin\app\controller\V1OrderController",
                    "pid" => $id,
                    "created_at" => "",
                    "updated_at" => "",
                    "href" => "/app/admin/v1-node/orderlist?line_id=" . $value['id'],
                    "type" => 1,
                    "weight" => 0,
                    "user_status" => 1,
                    "name" => '所有订单',
                    "value" => (integer)$line_id + 2,
                ],
                [
                    'id' => (integer)$line_id + 3,
                    "title" => '所有节点',
                    "icon" => "",
                    "key" => "plugin\admin\app\controller\V1OrderController",
                    "pid" => $id,
                    "created_at" => "",
                    "updated_at" => "",
                    "href" => "/app/admin/v1-node/orderdetail?line_id=" . $value['id'],
                    "type" => 1,
                    "weight" => 0,
                    "user_status" => 1,
                    "name" => '所有节点',
                    "value" => (integer)$line_id + 3,
                ],
                [
                    'id' => (integer)$line_id + 4,
                    "title" => '节点过期',
                    "icon" => "",
                    "key" => "plugin\admin\app\controller\V1OrderController",
                    "pid" => $id,
                    "created_at" => "",
                    "updated_at" => "",
                    "href" => "/app/admin/v1-node/orderdetailexpire?line_id=" . $value['id'],
                    "type" => 1,
                    "weight" => 0,
                    "user_status" => 1,
                    "name" => '节点过期',
                    "value" => (integer)$line_id + 4,
                ],
                [
                    'id' => (integer)$line_id + 5,
                    "title" => '节点调换记录',
                    "icon" => "",
                    "key" => "plugin\admin\app\controller\V1OrderController",
                    "pid" => $id,
                    "created_at" => "",
                    "updated_at" => "",
                    "href" => "/app/admin/v1-node/exchangelist?line_id=" . $value['id'],
                    "type" => 1,
                    "weight" => 0,
                    "user_status" => 1,
                    "name" => '节点调换记录',
                    "value" => (integer)$line_id + 5,
                ],
                [
                    'id' => (integer)$line_id + 6,
                    "title" => '节点退款',
                    "icon" => "",
                    "key" => "plugin\admin\app\controller\V1OrderController",
                    "pid" => $id,
                    "created_at" => "",
                    "updated_at" => "",
                    "href" => "/app/admin/v1-node/refundlist?line_id=" . $value['id'],
                    "type" => 1,
                    "weight" => 0,
                    "user_status" => 1,
                    "name" => '节点退款',
                    "value" => (integer)$line_id + 6,
                ],
                [
                    'id' => (integer)$line_id  + 7,
                    "title" => '导入(续费/改密)',
                    "icon" => "",
                    "key" => "plugin\admin\app\controller\V1OrderController",
                    "pid" => $id,
                    "created_at" => "",
                    "updated_at" => "",
                    "href" => "/app/admin/v1-node/import?line_id=" . $value['id'],
                    "type" => 1,
                    "weight" => 0,
                    "user_status" => 1,
                    "name" => '导入(续费/改密)',
                    "value" => (integer)$line_id  + 7,
                ],
//                [
//                    'id' => (integer)$line_id + 8,
//                    "title" => 'IP黑名单',
//                    "icon" => "",
//                    "key" => "plugin\admin\app\controller\V1OrderController",
//                    "pid" => $id,
//                    "created_at" => "",
//                    "updated_at" => "",
//                    "href" => "/app/admin/v1-node/iptrace?line_id=" . $value['id'],
//                    "type" => 1,
//                    "weight" => 0,
//                    "user_status" => 1,
//                    "name" => 'IP黑名单',
//                    "value" => (integer)$line_id + 8,
//                ],
            ];
            $children[$key]['children'] = $line_children;
        }
        $children_count = count($children);
        $children_two = [
//            [
//                'id' => (integer)$data_2 + $children_count + 1,
//                "title" => '导入(续费/改密)',
//                "icon" => "",
//                "key" => "plugin\admin\app\controller\V1OrderController",
//                "pid" => $data_2,
//                "created_at" => "",
//                "updated_at" => "",
//                "href" => "/app/admin/v1-node/import",
//                "type" => 1,
//                "weight" => 0,
//                "user_status" => 1,
//                "name" => '导入(续费/改密)',
//                "value" => (integer)$data_2 + $children_count + 1,
//            ],
            [
                'id' => (integer)$data_2 + $children_count + 2,
                "title" => 'API提取',
                "icon" => "",
                "key" => "plugin\admin\app\controller\V1OrderController",
                "pid" => $data_2,
                "created_at" => "",
                "updated_at" => "",
                "href" => "/app/admin/v1-node/apiextract",
                "type" => 1,
                "weight" => 0,
                "user_status" => 1,
                "name" => 'API提取',
                "value" => (integer)$data_2 + $children_count + 2,
            ]
        ];
        $children = array_merge($children, $children_two);
        $data[2]['children'] = $children;

        $menus = array_merge($data, $menus);
        return $menus;
    }

}
